﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AnalysisTests
{
	public static class TestSupport
	{
		/// <summary>
		/// Run the analysis on the given exe, compare the internal report and the client info as needed. Report any failures.
		/// </summary>
		public static void TestWithOutput(string exename)
		{
			CmdLineAnalyzer.AnalyzeAndReportSingleExecFile(exename, true);

			string outputdir = CmdLineAnalyzer.DUMP_DIR;
			string cmpdir = System.IO.Path.Combine(CmdLineAnalyzer.RESULT_DIR_FULLCTX, System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(exename), null) + @"\");

			//check the results
			CheckResultsIdentical(System.IO.Path.Combine(outputdir, "resdata.output"), System.IO.Path.Combine(cmpdir, "resdata.output"));
			CheckResultsIdentical(System.IO.Path.Combine(outputdir, "mutationnullity.output"), System.IO.Path.Combine(cmpdir, "mutationnullity.output"));
			CheckResultsIdentical(System.IO.Path.Combine(outputdir, "specs.output"), System.IO.Path.Combine(cmpdir, "specs.output"));
		}

		private static void CheckResultsIdentical(string newresultsfile, string checkwithfile)
		{
			string newres = System.IO.File.ReadAllText(newresultsfile);
			string checkval = System.IO.File.ReadAllText(checkwithfile);

			Assert.AreEqual(checkval, newres);
		}
	}
}
